﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="../bootstrap/js/jquery.min.js"></script>
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <!--[if lt IE 9]>
        <script src="bootstrap/js/html5shiv.min.js"></script>
        <script src="bootstrap/js/respond.min.js"></script>
    <![endif]-->
    <script src="../config.js"></script>
    <script src="../bootstrap/js/Common.js"></script>
    <script src="../bootstrap/js/controls.js"></script>
    <script type="text/javascript">
        var index = GetUrlParam("index");
        var identity = GetUrlParam("identity");
        $(function () {
            var formOption = {
                items: [
                    {
                        name: "name",
                        title: "触发器名称",
                        field: "name",
                        type: "text"

                    },
                    {
                        name: "index",
                        title: "触发次序",
                        field: "index",
                        type: "text",
                        readonly: GetUrlParam("mode") != "1" 
                    },
                    {
                        name: "testFunc",
                        title: "条件",
                        field: "testFunc",
                        type: "text"
                    }, {
                        name: "parameters",
                        title: "参数",
                        field: "parameters",
                        type: "text"
                    }, {
                        name: "actionType",
                        title: "操作类型",
                        field: "actionType",
                        type: "text"
                    }, {
                        name: "actionScript",
                        title: "触发器脚本",
                        field: "actionScript",
                        type: "textarea"
                    } 
                ]
            };
            $(".form-horizontal").form(formOption).load(host_name + "rule/single?gettrigger="+index+"&id="+identity,
                function() {
                    document.getElementById("index").addEventListener("keyup",
                        function () {
                            this.value = this.value.replace(/\D/g, '');
                        }
                    );
                    if (GetUrlParam("mode") == "1") {
                        $("#name").val("");
                    }
                });
        });
        function Save() {
            var surl = host_name + "rule/updatetrigger";
            var symbol=$("#testFunc").val();
            switch (symbol) 
            { 
                case "=":symbol="EQ"; 
                    break; 
                default:symbol=$("#testFunc").val()
            }
            var action = GetUrlParam("mode") == "1" ? "add" : "update";
            var trigger = JSON.stringify({ index: $('#index').val(), name: $('#name').val(), testFunc: symbol, parameters: $('#parameters').val(), actionType: $('#actionType').val(), actionScript: $('#actionScript').val() });
            $.ajax({
                url: surl,
                type: "post",
                async:false,
                data: JSON.stringify({ Id:identity, Trigger: trigger, Action: action }),
                success: function (data) { 
                
                }
            });
        }
    </script>
</head>
<body>
    <div class="container">
        <form class="form-horizontal"></form>
    </div>
</body>
</html>